<template>
  <div class="pilaing">
    <el-dialog
      title="批量导入"
      :close-on-click-modal="false"
      :visible.sync="dialogTableVisible"
      width="400px">
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="headers"
        :action="baseURL"
        :data="uploadData"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-link type="info" style="font-size:12px ;color: #330099" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button size="medium" @click="cancel">取 消</el-button>
        <el-button size="medium" type="primary" @click="submitFileForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import request from '@/utils/request'

export default {
  props: ['daoruData'],
  name: "Role",
  data() {
    return {
      dialogTableVisible:true,
      headers: { Authorization: "Bearer " + localStorage.getItem('token')},
      baseURL:localStorage.getItem('baseURL')+"/wh/inventoryLoss/import",
      uploadData:{
        warehouseId:''
      }
    };
  },
  watch: {
    dialogTableVisible: function () {
      this.dialogTableVisible = true;//始终让他为true;
      this.cancel();//隐藏
    },
  },
  created() {
    console.log('接受',this.daoruData)
    this.uploadData.warehouseId = this.daoruData.warehouseId


  },
  mounted() {


  },
  methods: {
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    //下载模板
    importTemplate() {
      window.location.href = "http://piwx.llmaicai.com/excel/pandian.xlsx";
      // request({
      //   url: 'http://piwx.llmaicai.com/excel/pandian.xlsx',
      //   method: 'get',
      // })
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      console.log('文件上传中')
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      if(response.code==200){
        this.$message({
          type: 'success',
          message:response.msg
        });
        var arr=[]
        arr = response.data.records
        this.$emit('daoruback',arr)//将submitModel的值传给父组件
      }else {
        this.$emit('daoruback','')//将submitModel的值传给父组件
        this.$message({
          type: 'warning',
          message:response.msg
        });
      }


    },
    //隐藏
    cancel:function(){
      // this.determine()
      this.$emit('daoruback','')//将submitModel的值传给父组件
    },

  }
};
</script>
<style scoped>
.pilaing .el-link--inner {
  color: #330099;
}



</style>
